<!--
 * @Description: 
 * @Author: charles
 * @Date: 2021-11-09 11:14:33
 * @LastEditors: charles
 * @LastEditTime: 2021-11-09 11:36:29
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>事件</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/react/17.0.2/umd/react.production.min.js"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js"></script>
  <script src="https://cdn.bootcss.com/babel-standalone/6.26.0/babel.min.js"></script>
</head>
<body>
  <div id="app"></div>
  <script type="text/babel">
    class App extends React.Component {
      constructor(props){
        super(props);
        this.state = {};
      }

      clickHandler(event,item){
        event.preventDefault(); // 阻止默认行为,停止冒泡、获取值
        console.log(event);
        console.log(this);
        alert(item);
      }

      render(){
        return (
          <div>
            <h2>事件</h2>  
            <ul>
              {
                ['terry','larry','tom'].map(item =>{
                  return (
                    <li key={item}>
                      <a href="" onClick={ ()=>{
                        this.clickHandler(event,item)
                      } }>{item}</a>
                    </li>
                  )
                })
              }  
            </ul>
          </div>
        )
      }
    }
    ReactDOM.render(<App/>,document.getElementById('app'));



  </script>
</body>
</html>